package com.ss.android.article.base.feature.app.e;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Pair;
import android.webkit.WebView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.frameworks.b.a.ComponentsManifest;
import com.ss.android.account.Spipe;
import com.ss.android.account.b.OnAccountRefreshListener;
import com.ss.android.account.model.BaseUser;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.main.IRecentFragment;
import com.ss.android.article.base.feature.main.IFeedManager;
import com.ss.android.article.base.feature.pgc.PgcActivity;
import com.ss.android.article.base.feature.search.BaseDiscoverActivity;
import com.ss.android.article.base.feature.subscribe.b.SubscribeManager;
import com.ss.android.article.base.feature.subscribe.model.EntryItem;
import com.ss.android.article.base.feature.subscribe.model.SubscribeData;
import com.ss.android.article.base.feature.update.b.UpdateItemMgr;
import com.ss.android.article.browser.R;
import com.ss.android.article.share.entity.BaseShareContent;
import com.ss.android.article.share.entity.ShareImageBean;
import com.ss.android.common.AbsApiThread;
import com.ss.android.common.app.IComponent;
import com.ss.android.common.callback.CallbackCenter;
import com.ss.android.common.download.DownloadAdapterProxy;
import com.ss.android.common.download.DownloadShortInfo;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.common.util.UrlBuilder;
import com.ss.android.messagebus.SubscriptionRouter;
import com.ss.android.newmedia.BaseAppData;
import com.ss.android.newmedia.activity.browser.BrowserActivity;
import com.ss.android.newmedia.e.JsObject;
import com.ss.android.newmedia.util.AppUtil;
import com.ss.android.pay.PayException;
import com.ss.android.pay.UnsupportedPayException;
import com.ss.android.pay.WXNotInstalledException;
import com.ss.android.pay.j;
import com.ss.android.pay.l;
import com.tencent.mm.opensdk.openapi.IWXAPI;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class TTAndroidObject extends JsObject implements com.ss.android.account.b.a.b.b$a, OnAccountRefreshListener, SubscribeManager.SubscribeDataChangeListener {
    private AppData mAppData;
    public LinkedList<Pair<Long, String>> mSubscribeQueue;
    public String c;
    private WeakReference<TTJsInterface> mTTJsInterfaceRef;
    private com.ss.android.pay.j m;
    private Spipe mSpipe;
    private boolean mIsLogin;
    private boolean p;

    static {
        HOST_SET.put("article_impression", Boolean.TRUE);
    }

    public TTAndroidObject(AppData appData, Context context) {
        super(appData, context);
        this.mSubscribeQueue = new LinkedList();
        this.mIsLogin = false;
        this.p = false;
        if (context != null) {
            SubscribeManager.init(context);
            SubscribeManager.getInstance().addSubscribeDataChangeListener(this);
        }

        this.mSpipe = Spipe.inst();
        this.mIsLogin = this.mSpipe.isLogin;
        this.mAppData = appData;
        this.mSpipe.addOnAccountRefreshListener(((OnAccountRefreshListener) this));
    }

    public static long optLong(JSONObject jsonObject, String key) {
        if (jsonObject != null) {
            String longValue = jsonObject.optString(key);
            try {
                return Long.valueOf(longValue).longValue();
            } catch (NumberFormatException numberFormatException) {

            }
        }
        return 0L;
    }

    private void a(long arg4, String arg6) {
        if (this.mSubscribeQueue.size() > 30) {
            this.mSubscribeQueue.removeFirst();
        }
        this.mSubscribeQueue.add(new Pair(Long.valueOf(arg4), arg6));
    }

    static void a(TTAndroidObject arg0, String arg1, JSONObject arg2) {
        arg0.sendCallbackMsg(arg1, arg2);
    }

    private void a(boolean arg5, JSONObject arg6) {
        int v0_1;
        String v1;
        if (arg6 != null && mAppData.getLong(arg6, "id") > 0) {
            try {
                v1 = "status";
                if (arg5) {
                    v0_1 = 1;
                } else {
                    v0_1 = 0;
                }
                arg6.put(v1, v0_1);
                this.c("pgc_action", arg6);
            } catch (JSONException v0) {
                v0.printStackTrace();
            }
        }
    }

    private boolean a(long arg8) {
        Iterator<Pair<Long, String>> v2 = this.mSubscribeQueue.iterator();
        do {
            if (v2.hasNext()) {
                if (v2.next().first.longValue() != arg8) {
                    continue;
                }

                break;
            } else {
                return false;
            }
        }
        while (true);

        boolean v0 = true;
        return v0;
    }

    private boolean a(boolean arg15, JSONObject arg16, JSONObject arg17, String arg18) throws JSONException {
        boolean v2_1;
        if (arg16 == null || arg17 == null) {
            v2_1 = false;
        } else {
            WebView v2 = this.getWebView();
            String v8 = v2 != null ? v2.getOriginalUrl() : null;
            if (v8 != null && (v8.startsWith("file:///android_asset/article/"))) {
                long v10 = mAppData.getLong(arg16, "uid");
                long v6 = mAppData.getLong(arg16, "id");
                long v4 = arg16 != null ? mAppData.getLong(arg16, "source") : 0;
                if (v10 > 0 && (android.support.design.a.isComponentActive(((JsObject) this).getActivityCtx()))) {
                    Object v3 = this.mContextRef.get();
                    if (!NetworkUtils.isNetworkAvailable(((Context) v3))) {
                        arg17.put("code", 0);
                        v2_1 = true;
                    } else {
                        if (!this.p && v3 != null) {
                            this.p = true;
                            com.ss.android.account.b.a.b.a(((Context) v3)).a(((com.ss.android.account.b.a.b.b$a) this));
                        }

                        BaseUser baseUser = new BaseUser(v10);
                        baseUser.mNewSource = v4 > 0 ? String.valueOf(v4) : "30";
                        baseUser.mMediaId = v6;
                        String v2_2 = null;
                        if ((v3 instanceof com.ss.android.article.base.feature.detail2.h)) {
                            v2_2 = ((com.ss.android.article.base.feature.detail2.h) v3).l();
                        }

                        if (this.a(v10)) {
                            arg17.put("code", 0);
                            return true;
                        }

                        this.a(v10, arg18);
                        if (AppData.getInstance().getAbSettings().isAppLogNew()) {
                            CallbackCenter.notifyCallback(BaseAppData.callbackTypeArticleSubOrUnsub, new Object[]{BaseAppData.callbackTypeArticleSubOrUnsub, Boolean.valueOf(arg15)});
                        }

                        String item_id = Uri.parse(v8).getQueryParameter("item_id");
                        com.ss.android.account.b.a.b.a(((Context) v3)).a(baseUser, arg15, v2_2, ((Context) v3));
                        v2_2 = arg16.optString("concern_type");
                        if (v3 != null) {
                            JSONObject v10_1 = new JSONObject();
                            v10_1.put("item_id", item_id);
                            if (!android.support.design.a.isTextEmpty(v2_2)) {
                                v10_1.put("concern_type", v2_2);
                            }

                            item_id = "detail";
                            String v5 = arg15 ? "pgc_subscribe" : "pgc_unsubscribe";
                            MobClickCombiner.onEvent(((Context) v3), item_id, v5, v6, 0, v10_1);
                        }

                        v2_1 = false;
                    }

                    return v2_1;
                }

                arg17.put("code", 0);
                return true;
            }

            arg17.put("code", 0);
            v2_1 = true;
        }

        return v2_1;
    }

    public final void a(String arg3, long arg4, int arg6) {
        if (arg4 > 0 && arg3 != null && (this.p)) {
            try {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("type", arg3);
                jsonObject.put("id", arg4);
                jsonObject.put("status", arg6);
                this.b("page_state_change", jsonObject);
            } catch (Exception v0) {
            }
        }
    }

    public final String getJSAppName() {
        return "NewsArticle";
    }

    public void a(int arg1, int arg2, BaseUser arg3) {
    }

    public void handleUri(Uri arg11) {
        long v8 = 0;
        if (arg11 != null) {
            try {
                String host = arg11.getHost();
                if (android.support.design.a.isTextEmpty(host)) {
                    return;
                }

                if ("article_impression".equals(host)) {
                    long v2 = android.support.design.a.x(arg11.getQueryParameter("groupid"));
                    long v0_2 = android.support.design.a.x(arg11.getQueryParameter("subjectid"));
                    long v4 = android.support.design.a.x(arg11.getQueryParameter("item_id"));
                    int v6 = android.support.design.a.d(arg11.getQueryParameter("aggr_type"), 0);
                    if (v0_2 <= v8) {
                        return;
                    }

                    if (v2 <= v8) {
                        return;
                    }

                    AppData.a(v0_2, v2, v4, v6);
                    return;
                }

                super.handleUri(arg11);
            } catch (Exception v0) {
            }
        }
    }

    public final void a(BaseUser arg1) {
    }

    public final void setTTJsInterface(TTJsInterface arg2) {
        this.mTTJsInterfaceRef = arg2 == null ? null : new WeakReference(arg2);
    }

    public final void onSubscribeDataChanged(SubscribeData subscribeData) {
        String v3_1;
        long v4_2;
        String itemId;
        int v0_2;
        int v1;
        String v5;
        JSONObject jsonObject;
        Object v0;
        Object v6 = null;
        int v12 = 2;
        int v2 = 1;
        if (subscribeData != null && subscribeData.a == 3) {
            Object v7 = (subscribeData.c instanceof EntryItem) ? subscribeData.c : v6;
            if (v7 == null) {
                return;
            }

            Iterator<Pair<Long, String>> v4 = this.mSubscribeQueue.iterator();
            do {
                if (v4.hasNext()) {
                    v0 = v4.next();
                    if (((Pair<Long, String>) v0).first.longValue() != ((EntryItem) v7).mId) {
                        continue;
                    }
                    v4.remove();
                    if (!android.support.design.a.isTextEmpty((String) ((Pair) v0).second)) {
                        try {
                            jsonObject = new JSONObject();
                            v5 = "code";
                            if (subscribeData.pgcSubscribeResult == 0) {
                                v1 = 1;
                            } else {
                                v1 = 0;
                            }
                            jsonObject.put(v5, v1);
                            jsonObject.put("id", ((EntryItem) v7).mId);
                            jsonObject.put("showToast", 1);
                            this.sendCallbackMsg((String) ((Pair) v0).second, jsonObject);
                            v0_2 = 1;
                        } catch (Exception v0_1) {
                            v0_2 = 1;
                        }
                    } else {
                        v0_2 = 0;
                    }
                    break;
                }
                v0_2 = 0;
                break;
            } while (true);
            if (subscribeData.pgcSubscribeResult == 0 && v0_2 == 0) {
                itemId = "pgc_action";
                v4_2 = ((EntryItem) v7).mId;
                if (!((EntryItem) v7).isSubscribed()) {
                    v2 = 0;
                }

                this.a(itemId, v4_2, v2);
            }

            if (subscribeData.pgcSubscribeResult != 0) {
                v0 = this.mContextRef.get();
                if (v0 != null) {
                    if (!((EntryItem) v7).isSubscribed()) {
                        v1 = android.support.design.a.m() == v12 ? R.string.toast_have_followed_failed : R.string.toast_have_subscribed_failed;
                        android.support.design.a.showImageToast(((Context) v0), v1, 0);
                    } else {
                        v1 = android.support.design.a.m() == v12 ? R.string.toast_have_unfollow_user : R.string.toast_have_unsubscribed_failed;
                        android.support.design.a.showImageToast(((Context) v0), v1, 0);
                    }
                }
            }

            v4_2 = ((EntryItem) v7).mId;
            boolean v3 = ((EntryItem) v7).isSubscribed();
            int v7_1 = subscribeData.pgcSubscribeResult;
            Context context = this.mContextRef.get();
            if (context == null) {
                return;
            }

            WebView webView = this.getWebView();
            itemId = webView != null ? webView.getOriginalUrl() : ((String) v6);
            String v2_1 = "";
            itemId = itemId == null || !itemId.startsWith("file:///android_asset/article/")
                    ? v2_1
                    : Uri.parse(itemId).getQueryParameter("item_id");
            if ((v3) && v7_1 == 0) {
                v3_1 = "pgc_subscribe_success";
            } else if (v3) {
                return;
            } else if (v7_1 != 0) {
                v3_1 = "pgc_subscribe_fail";
            } else {
                return;
            }

            try {
                JSONObject jo = new JSONObject();
                jo.put("item_id", itemId);
                MobClickCombiner.onEvent(((Context) context), "detail", v3_1, v4_2, 0, jo);
            } catch (Exception v0_1) {
            }
        }
    }

    public void addProtectedFeature(List<String> protectFeatureList) {
        super.addProtectedFeature(protectFeatureList);
        protectFeatureList.add("pay");
        protectFeatureList.add("addEventListener");
        protectFeatureList.add("page_state_change");
        protectFeatureList.add("addChannel");
        protectFeatureList.add("openHotsoon");
    }

    public final void a(JSONObject arg2) {
        super.a(arg2);
        this.getTTJsInterface();
        if (arg2 != null) {
        }
    }

    public boolean a(Context context) {
        return ((context instanceof BaseDiscoverActivity))
                || ((context instanceof PgcActivity))
                || ((context instanceof com.ss.android.article.base.feature.feed.i))
                || super.a(context);
    }

    public boolean processJsMsg(JSMessage jsMessage, JSONObject arg15) throws Exception {
        String v4_3;
        DownloadShortInfo v0_13;
        Activity v2_3;
        Activity v1_6;
        JSONObject v0_10;
        String v3_1;
        long v1_4;
        String v6_1 = null;
        long v2_1;
        String v1_3;
        String v0_9;
        int v0_8;
        Activity v0_7;
        final String v2;
        JSONObject v1;
        int v4 = 2;
        long v8 = 0;
        Object v6 = null;
        boolean v7 = false;
        Object v0 = this.mContextRef != null ? this.mContextRef.get() : v6;
        if ("pay".equals(jsMessage.func)) {
            v1 = jsMessage.params;
            v2 = jsMessage.callbackId;
            if (this.mContextRef != null && this.mContextRef.get() != null && ((this.mContextRef.get() instanceof Activity))) {
                v6 = this.mContextRef.get();
            }

            if (v6 == null) {
                return v7;
            }

            v1 = v1.optJSONObject("data");
            if (v1 == null) {
                UIUtils.showImageToast((Context) this.mContextRef.get(), R.drawable.close_popup_textpage, R.string.jq);
                return v7;
            }

            IWXAPI v0_1 = this.mAppData.l((Context) this.mContextRef.get());
            try {
                this.m = new j() {
                    public final void a(int arg4, String code) {
                        try {
                            JSONObject jsonObject = new JSONObject();
                            jsonObject.put("code", code);
                            TTAndroidObject.this.sendCallbackMsg(v2, jsonObject);
                            SubscriptionRouter.c(new com.ss.android.article.base.feature.detail2.event.a(arg4));
                        } catch (Throwable throwable) {
                            throwable.printStackTrace();
                        }
                    }
                };
                l v0_5 = com.ss.android.pay.k.a().a(((Activity) v6), v0_1, v1.toString(), this.m);
                if (v0_5 == null) {
                    return v7;
                }

                v0_5.b();
            } catch (PayException v0_2) {
                PayException v1_1 = v0_2;
                if (v1_1.getErrResId() <= 0) {
                    return v7;
                }

                UIUtils.showImageToast((Context) this.mContextRef.get(), R.drawable.close_popup_textpage, v1_1.getErrResId());
            } catch (UnsupportedPayException unsupportedPayException) {
                unsupportedPayException.printStackTrace();
            } catch (WXNotInstalledException wxNotInstalledException) {
                UIUtils.showImageToast((Context) this.mContextRef.get(), R.drawable.close_popup_textpage, R.string.toast_weixin_not_install);
            }

            return v7;
        }

        if ("media_like".equals(jsMessage.func)) {
            this.a(true, jsMessage.params);
            return v7;
        }

        if ("media_unlike".equals(jsMessage.func)) {
            this.a(false, jsMessage.params);
            return v7;
        }

        if ("do_media_like".equals(jsMessage.func)) {
            return this.a(true, jsMessage.params, arg15, jsMessage.callbackId);
        }

        if ("do_media_unlike".equals(jsMessage.func)) {
            return this.a(false, jsMessage.params, arg15, jsMessage.callbackId);
        }

        if ("is_visible".equals(jsMessage.func)) {
            Object v1_2 = this.mFragmentRef != null ? this.mFragmentRef.get() : v6;
            boolean v0_6 = (v1_2 instanceof IComponent) ? ((IComponent) v1_2).isActive() : false;
            if (!v0_6) {
                arg15.put("code", 0);
                return true;
            }

            v0_7 = this.getActivityCtx();
            v0_8 = !(v1_2 instanceof IRecentFragment) || !(v0_7 instanceof IFeedManager) || (((IFeedManager) v0_7).isPrimaryPage(((IRecentFragment) v1_2))) ? 1 : 0;
            arg15.put("code", v0_8);
            return true;
        }

        if ("is_login".equals(jsMessage.func)) {
            v0_9 = "code";
            int v7_1 = 0;
            if (this.mIsLogin) {
                v7_1 = 1;
            }

            arg15.put(v0_9, ((int) v7_1));
            return true;
        }

        if ("sharePanel".equals(jsMessage.func)) {
            v0_9 = "";
            if (jsMessage.params != null) {
                long v11 = mAppData.getLong(jsMessage.params, "id");
                v1_3 = jsMessage.params.optString("type");
                v2_1 = v11;
            } else {
                v2_1 = v8;
                v1_3 = v0_9;
            }

            if (v2_1 <= v8) {
                arg15.put("code", 0);
                return true;
            }

            v0_7 = this.getActivityCtx();
            if ((v0_7 instanceof PgcActivity)) {
                ((PgcActivity) v0_7).a(v2_1);
            } else if (this.getTTJsInterface() != null) {
                this.getTTJsInterface().a(v2_1, v1_3);
            }

            arg15.put("code", 1);
            return true;
        }

        if ("slideableWidget".equals(jsMessage.func)) {
            this.getTTJsInterface();
            return v7;
        }

        if ("share_pgc".equals(jsMessage.func)) {
            v2_1 = jsMessage.params != null ? mAppData.getLong(jsMessage.params, "id") : v8;
            if (v2_1 <= v8) {
                arg15.put("code", 0);
                return true;
            }

            v0_7 = this.getActivityCtx();
            if ((v0_7 instanceof PgcActivity)) {
                ((PgcActivity) v0_7).a(v2_1);
            } else if (this.getTTJsInterface() != null) {
                this.getTTJsInterface().a(v2_1);
            }

            arg15.put("code", 1);
            return true;
        }

        if ("shareInfo".equals(jsMessage.func)) {
            if (jsMessage.params == null) {
                return v7;
            }

            BaseShareContent BaseShareContent = new BaseShareContent();
            String title = jsMessage.params.optString("title");
            v1_3 = jsMessage.params.optString("desc");
            v2 = jsMessage.params.optString("image");
            title = android.support.design.a.isTextEmpty(title) ? "【分享页面】" : "【" + title + "】";
            BaseShareContent.setTitle(title);
            String text = android.support.design.a.isTextEmpty(v1_3) ? jsMessage.params.optString("url") : v1_3;
            BaseShareContent.setText(text);
            BaseShareContent.setTargetUrl(jsMessage.params.optString("url"));
            String imageUrl = android.support.design.a.isTextEmpty(v2) ? "http://p3.pstatp.com/thumb/96a001eaaa24388a0d6" : v2;
            BaseShareContent.setMedia(new ShareImageBean(imageUrl));
            this.getTTJsInterface().a(BaseShareContent);
            return v7;
        }

        if ("addEventListener".equals(jsMessage.func)) {
            if (jsMessage.params != null) {
                v6_1 = jsMessage.params.optString("name");
            }

            if (("page_state_change".equals(v6)) && !this.p && v0 != null) {
                this.p = true;
                com.ss.android.account.b.a.b.a(((Context) v0)).a(((com.ss.android.account.b.a.b.b$a) this));
            }

            arg15.put("code", 1);
            return true;
        }

        if ("page_state_change".equals(jsMessage.func)) {
            arg15.put("code", 1);
            if (jsMessage.params != null) {
                v0_9 = jsMessage.params.optString("type");
                if (!"pgc_action".equals(v0_9) && !"user_action".equals(v0_9) && !"forum_action".equals(v0_9) && !"concern_action".equals(v0_9) && !"wenda_rm".equals(v0_9) && !"wenda_digg".equals(v0_9) && !"block_action".equals(v0_9) && !"stock_action".equals(v0_9) && !"wenda_bury".equals(v0_9) && !"live_follow_action".equals(v0_9)) {
                    return true;
                }

                this.c(v0_9, jsMessage.params);
            }

            return true;
        }

        if (!"panelDislike".equals(jsMessage.func) && !"panelClose".equals(jsMessage.func)) {
            if ("panelRefresh".equals(jsMessage.func)) {
                if (jsMessage.params != null) {
                    v1_4 = mAppData.getLong(jsMessage.params, "id");
                    v3_1 = jsMessage.params.optString("category");
                } else {
                    v1_4 = v8;
                    v3_1 = ((String) v6);
                }

                if (v1_4 <= v8) {
                    return v7;
                }

                if (android.support.design.a.isTextEmpty(v3_1)) {
                    return v7;
                }

                this.mAppData.a(v1_4, v3_1, false, true);
            } else {
                if ("search".equals(jsMessage.func)) {
                    if (jsMessage.params == null) {
                        return v7;
                    }

                    v0_9 = jsMessage.params.optString("keyword");
                    jsMessage.params.optString("type");
                    if (this.getTTJsInterface() == null) {
                        return v7;
                    }

                    if (TextUtils.isEmpty(((CharSequence) v0_9))) {
                        return v7;
                    }

                    this.getTTJsInterface().a(v0_9);
                    return v7;
                }

                if ("panelHeight".equals(jsMessage.func)) {
                    v0_10 = jsMessage.params;
                    TTJsInterface v1_5 = this.getTTJsInterface();
                    if (v0_10 == null) {
                        return v7;
                    }

                    if (v1_5 == null) {
                        return v7;
                    }

                    v0_10.optInt("value");
                    return v7;
                }

                if ("update_share".equals(jsMessage.func)) {
                    v0_10 = jsMessage.params;
                    v1_6 = this.getActivityCtx();
                    if (v0_10 == null) {
                        return v7;
                    }

                    if (v1_6 == null) {
                        return v7;
                    }

                    JSONObject v2_2 = v0_10.optJSONObject("data");
                    if (v2_2 == null) {
                        return v7;
                    }

                    v0_10.optLong("uid");
                    v3_1 = v0_10.optString("event_name");
                    AbsApiThread.optBoolean(v0_10, "from_detail", false);
                    if (v2_2 != null) {
                        long v4_1 = v2_2.optLong("id");
                        if (v4_1 > v8) {
                            com.ss.android.article.base.feature.update.a.d v0_11 = new com.ss.android.article.base.feature.update.a.d(v4_1);
                            if (v0_11.a(v2_2)) {
                                Spipe.inst();
                                com.ss.android.article.base.feature.e.k v6_2 = new com.ss.android.article.base.feature.e.k(v1_6, v0_11, v3_1);
                            }
                        }
                    }

                    if ((((com.ss.android.article.base.feature.e.k) v6)) == null) {
                        return v7;
                    }

                    ((com.ss.android.article.base.feature.e.k) v6).a();
                    return v7;
                }

                if ("displayRefreshTip".equals(jsMessage.func)) {
                    v0_10 = jsMessage.params;
                    v1_6 = this.getActivityCtx();
                    if (v0_10 == null) {
                        return v7;
                    }

                    if (v1_6 == null) {
                        return v7;
                    }

                    if (android.support.design.a.isTextEmpty(v0_10.optString("refresh_tips"))) {
                        return v7;
                    }

                    this.getTTJsInterface();
                    return v7;
                }

                if ("refreshdone".equals(jsMessage.func)) {
                    return v7;
                }

                if ("onLoaded".equals(jsMessage.func)) {
                    return v7;
                }

                if ("toast".equals(jsMessage.func)) {
                    v0_10 = jsMessage.params;
                    v1_6 = this.getActivityCtx();
                    if (v0_10 == null) {
                        return v7;
                    }

                    if (v1_6 == null) {
                        return v7;
                    }

                    try {
                        v2 = v0_10.optString("text");
                        v0_9 = v0_10.optString("icon_type");
                        if (android.support.design.a.isTextEmpty(v2)) {
                            return v7;
                        }

                        if (!android.support.design.a.isTextEmpty(v0_9)) {
                            v0_8 = "icon_success".equals(v0_9) ? R.drawable.doneicon_popup_textpage : R.drawable.close_popup_textpage;
                            android.support.design.a.showToast(((Context) v1_6), v2, v1_6.getResources().getDrawable(v0_8));
                            return v7;
                        }

                        android.support.design.a.a(((Context) v1_6), v2, null, 0);
                        return v7;
                    } catch (Exception v0_12) {
                        return v7;
                    }
                }

                if ("gamePause".equals(jsMessage.func)) {
                    v2_3 = this.getActivityCtx();
                    v0_10 = jsMessage.params;
                    if (v0_10 == null) {
                        return v7;
                    }

                    v0_9 = v0_10.optString("url");
                    if (v2_3 == null) {
                        return v7;
                    }

                    if (android.support.design.a.isTextEmpty(v0_9)) {
                        return v7;
                    }

                    v0_13 = DownloadAdapterProxy.inst().queryDownloadInfo(((Context) v2_3), v0_9);
                    if (v0_13 == null) {
                        return v7;
                    }

                    if (v0_13.b != v4 && v0_13.b != 1) {
                        return v7;
                    }

                    DownloadAdapterProxy.inst().handleStatusClick(((Context) v2_3), v0_13.b, v0_13.id, ((String) v6));
                    try {
                        v0_10 = new JSONObject();
                        v0_10.put("status", 1);
                        this.sendCallbackMsg(jsMessage.callbackId, v0_10);
                    } catch (Exception v0_12) {
                    }

                    return v7;
                }

                if ("gameContinue".equals(jsMessage.func)) {
                    v2_3 = this.getActivityCtx();
                    v0_10 = jsMessage.params;
                    if (v0_10 == null) {
                        return v7;
                    }

                    v0_9 = v0_10.optString("url");
                    if (v2_3 == null) {
                        return v7;
                    }

                    if (android.support.design.a.isTextEmpty(v0_9)) {
                        return v7;
                    }

                    v0_13 = DownloadAdapterProxy.inst().queryDownloadInfo(((Context) v2_3), v0_9);
                    if (v0_13 != null && v0_13.b == 4) {
                        DownloadAdapterProxy.inst().handleStatusClick(((Context) v2_3), v0_13.b, v0_13.id, ((String) v6));
                        try {
                            v0_10 = new JSONObject();
                            v0_10.put("status", 2);
                            this.sendCallbackMsg(jsMessage.callbackId, v0_10);
                        } catch (Exception v0_12) {
                        }

                        return v7;
                    }

                    if (v0_13 == null) {
                        return v7;
                    }

                    if (v0_13.b != 1) {
                        if (v0_13.b == v4) {
                        } else {
                            return v7;
                        }
                    }

                    try {
                        v0_10 = new JSONObject();
                        v0_10.put("status", 2);
                        this.sendCallbackMsg(jsMessage.callbackId, v0_10);
                    } catch (Exception v0_12) {
                    }

                    return v7;
                }

                if ("requestChangeOrientation".equals(jsMessage.func)) {
                    if (jsMessage.params == null) {
                        return v7;
                    }

                    int v1_7 = jsMessage.params.optInt("orientation");
                    if (v1_7 != 0 && v1_7 != 1) {
                        return v7;
                    }

                    v0 = this.mContextRef != null ? this.mContextRef.get() : v6;
                    if (v0 == null) {
                        return v7;
                    }

                    if (!(v0 instanceof BrowserActivity)) {
                        return v7;
                    }

                    if (v1_7 == 0) {
                        ((BrowserActivity) v0).a(1);
                        return v7;
                    }

                    if (v1_7 != 1) {
                        return v7;
                    }

                    ((BrowserActivity) v0).a(v4);
                    return v7;
                }

                if ("openCommodity".equals(jsMessage.func)) {
                    v1 = jsMessage.params;
                    if (v1 == null) {
                        return v7;
                    }

                    v0 = this.mContextRef != null ? this.mContextRef.get() : v6;
                    if (v0 == null) {
                        return v7;
                    }

                    v2 = v1.optString("type");
                    Boolean v3_2 = Boolean.valueOf(false);
                    if (!android.support.design.a.isTextEmpty(v2)) {
                        Logger.d("TTAndroidObject", "web get params : " + v1.toString());
                        if ("taobao".equals(v2)) {
                            AppData.Y();
                        }

                        if ("jingdong".equals(v2)) {
                            AppData.X();
                        }

                        if (!"kepler".equals(v2)) {
                        } else {
                            AppData.Z();
                        }
                    }
                    if (v3_2.booleanValue()) {
                        return v7;
                    }

                    if (!v1.has("url")) {
                        return v7;
                    }

                    v1_3 = v1.optString("url");
                    if (v0 == null) {
                        return v7;
                    }

                    if (android.support.design.a.isTextEmpty(v1_3)) {
                        return v7;
                    }

                    if (!(v0 instanceof Activity)) {
                        v0 = v6;
                    }

                    if (v0 == null) {
                        return v7;
                    }

                    if (!android.support.design.a.isComponentActive(((Context) v0))) {
                        return v7;
                    }

                    AppUtil.b(((Context) v0), v1_3);
                    return v7;
                }

                if ("adInfo".equals(jsMessage.func)) {
                    arg15.put("cid", this.queryContextData("cid"));
                    arg15.put("log_extra", this.queryContextData("log_extra"));
                    return true;
                }

                if ("user_follow_action".equals(jsMessage.func)) {
                    JSONObject v4_2 = jsMessage.params;
                    String v10 = jsMessage.callbackId;
                    if (v4_2 == null) {
                        return v7;
                    }

                    if (arg15 == null) {
                        return v7;
                    }

                    WebView v0_14 = this.getWebView();
                    v0_9 = v0_14 != null ? v0_14.getOriginalUrl() : ((String) v6);
                    if (v0_9 != null && (v0_9.startsWith("file:///android_asset/article/"))) {
                        v2_1 = v4_2 != null ? mAppData.getLong(v4_2, "id") : v8;
                        if (v2_1 > v8 && (android.support.design.a.isComponentActive(((JsObject) this).getActivityCtx()))) {
                            v0 = this.mContextRef.get();
                            if (!NetworkUtils.isNetworkAvailable(((Context) v0))) {
                                android.support.design.a.showImageToast(((Context) v0), R.string.ss_error_no_connections, R.drawable.close_popup_textpage);
                                arg15.put("code", 0);
                                v7 = true;
                            } else {
                                if (!this.mSpipe.isLogin && ((v0 instanceof Activity))) {
                                    Spipe.a(((Activity) v0), ((Bundle) v6));
                                    arg15.put("code", 0);
                                    return true;
                                }

                                if (!this.p && v0 != null) {
                                    this.p = true;
                                    com.ss.android.account.b.a.b.a(((Context) v0)).a(((com.ss.android.account.b.a.b.b$a) this));
                                }

                                String v8_1 = v4_2.optString("action");
                                BaseUser v9 = new BaseUser(v2_1);
                                if ((v0 instanceof com.ss.android.article.base.feature.detail2.h)) {
                                    v6_1 = ((com.ss.android.article.base.feature.detail2.h) v0).l();
                                }

                                if (this.a(v2_1)) {
                                    arg15.put("code", 0);
                                    return true;
                                }

                                this.a(v2_1, v10);
                                if (!TextUtils.isEmpty(v4_2.optString("source"))) {
                                    v9.mNewSource = v4_2.optString("source");
                                }

                                com.ss.android.account.b.a.b.a(((Context) v0)).a(v9, "dofollow".equals(v8_1), ((String) v6_1));
                            }

                            return v7;
                        }

                        arg15.put("code", 0);
                        return true;
                    }

                    arg15.put("code", 0);
                    return true;
                }

                if ("openHotsoon".equals(jsMessage.func)) {
                    v0_10 = jsMessage.params;
                    if (v0_10 != null && this.mContextRef != null && this.mContextRef.get() != null) {
                        v1_3 = v0_10.optString("type");
                        if ("room".equals(v1_3)) {
                            v0_10 = v0_10.optJSONObject("args");
                            if (v0_10 != null) {
                                v0_9 = v0_10.optString("room_id");
                                UrlBuilder v1_8 = new UrlBuilder("sslocal://huoshan");
                                v1_8.addParam("room_id", v0_9);
                                AppUtil.b((Context) this.mContextRef.get(), v1_8.build());
                            }
                        } else if ("charge".equals(v1_3)) {
                            if (!Spipe.inst().isLogin) {
                                ComponentsManifest.findComponent(com.ss.android.account.v2.bb.class).startAccountLoginActivity(this.getActivityCtx());
                            } else {
                                AppUtil.b((Context) this.mContextRef.get(), new UrlBuilder("sslocal://huoshancharge").build());
                            }
                        }
                    }

                    return true;
                }

                v7 = super.processJsMsg(jsMessage, arg15);
            }

            return v7;
        }

        if (jsMessage.params != null) {
            v2_1 = mAppData.getLong(jsMessage.params, "id");
            v4_3 = jsMessage.params.optString("category");
        } else {
            v2_1 = v8;
            v4_3 = ((String) v6);
        }

        if (v2_1 > v8 && !android.support.design.a.isTextEmpty(v4_3)) {
            this.mAppData.a(v2_1, v4_3, true, "panelDislike".equals(jsMessage.func));
        }

        return v7;
    }

    public final boolean a(String arg4) {
        boolean v0 = true;
        if (arg4 == null || !arg4.startsWith("file:///android_asset/article/")) {
            if (!TTUtils.isValidUrl(arg4)) {
                return false;
            }

            try {
                String v2 = Uri.parse(arg4).getHost();
                if (v2 == null) {
                    return false;
                }

                if (com.ss.android.article.base.feature.app.a.c.a(v2)) {
                    return v0;
                }
            } catch (Exception v0_1) {
                Logger.throwExceptionInDebug(((Throwable) v0_1));
            }

            v0 = super.a(arg4);
        }

        return v0;
    }

    public final void b() {
        super.b();
        try {
            SubscribeManager.getInstance().b(this);
        } catch (Throwable v0) {
        }

        Object v0_1 = this.mContextRef != null ? this.mContextRef.get() : null;
        if (v0_1 != null && (this.p)) {
            com.ss.android.account.b.a.b.a(((Context) v0_1)).b(this);
        }

        if (this.mSpipe != null) {
            this.mSpipe.b(((OnAccountRefreshListener) this));
        }
    }

    public void addPublicFeature(List<String> arg2) {
        super.addPublicFeature(arg2);
        arg2.add("is_visible");
        arg2.add("is_login");
        arg2.add("gamePause");
        arg2.add("gameContinue");
    }

    private void c(String arg12, JSONObject arg13) {
        Object v0_3;
        String v0_2;
        Object v6_1;
        Object v1_2;
        int v9;
        long v4;
        int v0 = -1;
        long v6 = 0;
        if (arg13 != null) {
            v4 = mAppData.getLong(arg13, "id");
            v9 = arg13.optInt("status", v0);
        } else {
            v4 = v6;
            v9 = v0;
        }
        if (v4 > v6 && (v9 == 0 || v9 == 1)) {
            boolean v0_1 = android.support.design.a.isComponentActive(((JsObject) this).getActivityCtx()) ? true : android.support.design.a.isComponentActive(((JsObject) this).mAppData.aO());
            if (v0_1) {
                if ("pgc_action".equals(arg12)) {
                    v0_1 = v9 == 1 ? true : false;
                    CallbackCenter.notifyCallback(BaseAppData.callbackTypeSubscribePGCAddOrDelete, new Object[]{BaseAppData.callbackTypeSubscribePGCAddOrDelete, Boolean.valueOf(v0_1), Long.valueOf(v4)});
                    SubscribeManager v1 = SubscribeManager.getInstance();
                    SubscribeManager.checkUIThread();
                    v1.c.a(v4, v0_1);
                    com.ss.android.article.common.a.a.a.a();
                } else if ("forum_action".equals(arg12)) {

                } else if ("concern_action".equals(arg12)) {
                    v0 = v9 == 1 ? 1 : 0;
                    String v2 = arg13.optString("from", "");
                    JSONObject v8 = new JSONObject();
                    try {
                        v8.put("concern_id", v4);
                    } catch (JSONException v1_1) {
                        v1_1.printStackTrace();
                    }
                    v1_2 = this.mContextRef.get();
                    String v3 = !android.support.design.a.isTextEmpty(v2) ? "_" + v2 : v2;
                    v2 = "concern_page";
                    v3 = v0 != 0 ? "follow" + v3 : "unfollow" + v3;
                    MobClickCombiner.onEvent(((Context) v1_2), v2, v3, v4, v6, v8);
                    com.ss.android.article.common.a.a.a.a();
                } else if ("wenda_rm".equals(arg12)) {
                } else if ("wenda_digg".equals(arg12)) {
                    this.p = true;
                    v6_1 = this.mContextRef.get();
                    v0_2 = "";
                    if ((v6_1 instanceof com.ss.android.article.base.feature.detail2.h)) {
                        v0_2 = ((com.ss.android.article.base.feature.detail2.h) v6_1).l();
                    }
                    com.ss.android.article.common.b.b.a().a(String.valueOf(v4), v0_2, this.c, new com.ss.android.article.base.feature.app.e.c(this, arg12, v4, ((Context) v6_1)));
                } else if ("wenda_bury".equals(arg12)) {
                    this.p = true;
                    v6_1 = this.mContextRef.get();
                    v0_2 = "";
                    if ((v6_1 instanceof com.ss.android.article.base.feature.detail2.h)) {
                        v0_2 = ((com.ss.android.article.base.feature.detail2.h) v6_1).l();
                    }
                    com.ss.android.article.common.b.b.a().b(String.valueOf(v4), v0_2, this.c, new com.ss.android.article.base.feature.app.e.d(this, arg12, v4, ((Context) v6_1)));
                } else if ("donate_action".equals(arg12)) {
                } else if ("block_action".equals(arg12)) {
                    arg13.optInt("status");
                    long v2_1 = arg13.optLong("uid");
                    v0_3 = this.mContextRef.get();
                    if (v0_3 == null) {
                    } else if (v2_1 <= v6) {
                    } else {
                        UpdateItemMgr.getInstance(((Context) v0_3)).c(v2_1);
                    }
                } else if ("stock_action".equals(arg12)) {
                    this.mContextRef.get();
                    com.ss.android.article.common.a.a.a.a();
                } else if ("live_follow_action".equals(arg12)) {
                    this.mContextRef.get();
                    com.ss.android.article.common.a.a.a.a();
                }
            }
            Iterator v2_2 = sInsts.iterator();
            while (v2_2.hasNext()) {
                v0_3 = v2_2.next();
                v1_2 = null;
                if (!(v0_3 instanceof TTAndroidObject)) {
                    v0_3 = v1_2;
                }

                if (v0_3 == null) {
                    continue;
                }

                if (v0_3 == this) {
                    continue;
                }

                ((TTAndroidObject) v0_3).a(arg12, v4, v9);
            }
        }
    }

    public final void c(List arg2) {
        super.c(arg2);
        arg2.add("pay");
    }

    private TTJsInterface getTTJsInterface() {
        TTJsInterface ttJsInterface;
        if (this.mTTJsInterfaceRef != null) {
            ttJsInterface = this.mTTJsInterfaceRef.get();
        } else {
            ttJsInterface = null;
        }
        return ttJsInterface;
    }

    public void onAccountRefresh(boolean arg5, int arg6) {
        boolean isLogin = this.mSpipe.isLogin;
        if (isLogin != this.mIsLogin) {
            this.mIsLogin = isLogin;
            String event_id;
            if (isLogin) {
                event_id = "login";
            } else {
                event_id = "logout";
            }
            try {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("code", 1);
                this.b(event_id, jsonObject);
            } catch (Exception exception) {
            }
        }
    }
}

